import { getCategoryList } from '../../services/goods';
Page({
  data: {
    activeTab: 0,
    tabs: [],
    shopList: [],

  },
  onShow(option) {
    my.setNavigationBar({
      title: '分类',
      backgroundColor: '#4BA3F9'
    })
  },
  handleChange(index) {
    this.setData({
      activeTab: index,
    });
  },
  onChange(index) {
    this.setData({
      activeTab: index,
    });
    this.setData({
      shopList: this.data.tabs[index].childCategoryVOList,
    });
  },
  onLoad(query) {
    // 页面加载
    this.getCategoryList()
  },

  togoodslist(event) {
    console.log(event)
    my.navigateTo({
      url: '/pages/shopList/shopList?categoryId='+event.target.dataset.categoryId
    })
  },
  getCategoryList() {
    getCategoryList({}).then((res) => {
      res.data.forEach(element => {
        element.anchor = element.categoryName
        element.title = element.categoryName
        element.number = 0
      });
      this.setData({ tabs: res.data });
      if (res.data.length > 0) {
        this.setData({
          shopList: this.data.tabs[0].childCategoryVOList,
        });
      }
    })
  },
});
